package com.project.service.imp;

import com.project.bean.CutPageBean;
import com.project.bean.RoomBean;
import com.project.bean.StudentBean;
import com.project.dao.IFacilityDao;
import com.project.dao.IRoomDao;
import com.project.dao.IStudentDao;
import com.project.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class RoomServiceImp implements RoomService {
    @Autowired
    private IRoomDao dao;
    @Autowired
    private IFacilityDao ifDao;
    @Autowired
    private IStudentDao stuDao;

    @Override
    public CutPageBean<RoomBean> findByItem(Integer pageNO, String address, String state, String type, String live) {
        return dao.findByItem(pageNO, address, state, type, live);
    }

    @Override
    public RoomBean findById(Integer id) {
        RoomBean roomBean = dao.findById(id);
        roomBean.setStudent(stuDao.findByRoomId(id));
        return roomBean;
    }

    @Override
    public boolean del(Integer id) {
        if (dao.findById(id).getStuNum() != 0) {
            return false;
        } else {
            ifDao.del(id);
            dao.del(id);
            return true;
        }
    }

    @Override
    public List<RoomBean> findBySex(String sex) {
        return dao.findBySex(sex);
    }

    @Override
    public void add(RoomBean roomBean) {
        System.out.println(roomBean);
        dao.add(roomBean);
    }

    @Override
    public List<RoomBean> findAllOkRoom() {
        System.out.println(dao.findByOkRoom());
        return dao.findByOkRoom();
    }

    @Override
    public RoomBean findByName(String name) {
        return dao.findByName(name);
    }
}
